# -*- coding:utf-8 -*-
# @FileName  :dhcc_ent_batch_query.py
# @Time      :2020/12/10 16:24
# @Author    :Zhoujirong
# @Desc      : 批量查询

import datetime
import time

from common.utils import download
from common.log import Log
from biz.flow.ent_batch_query import EntBatchQueryRequest
from biz.cases.base_case import BaseCase
from common.utils import get_redis

class TestEntBatchQuery(BaseCase):
    '''批量查询测试用例'''
    data_file_name = 'batch_query.yaml'

    @classmethod
    def setUpClass(cls):
        cls.redis = get_redis()
        # cls.mysql = get_mysql()
        cls.cookie = BaseCase().get_token()

    def test_a_download(self):
        '''下载模板'''
        ret = EntBatchQueryRequest.download(self.cookie)
        Log.info(ret)
        size = download('企业批量模板文件dhcc_ent_batch_queryDtest_a_download%s.xls' % time.strftime('%Y%m%d%H%M%S', time.localtime()), ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)

    def test_b_upload(self):
        '''上传批量文件'''
        file = 'entTemplate.xlsx'
        ret = EntBatchQueryRequest.upload(file,file,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000',ret.code)
        self.assertEqual('上传成功',ret.msg)

    def get_page(self):
        '''检索'''
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_EQ_queryid = self.file_data.get('search_EQ_queryid')
        search_EQ_userid = self.file_data.get('search_EQ_userid')
        search_EQ_username = self.file_data.get('search_EQ_username')
        temp = '%s - %s'%(datetime.date.today(),datetime.date.today())
        search_GTE_LTE_queryTime_DATE_RANGE = temp
        search_IN_organ = self.file_data.get('search_IN_organ')
        search_operOrgRange = self.file_data.get('search_operOrgRange')
        search_EQ_errornum = self.file_data.get('search_EQ_errornum')
        ret = EntBatchQueryRequest.get_page(curPage,
                                            maxSize,
                                            search_EQ_queryid,
                                            search_EQ_userid,
                                            search_EQ_username,
                                            search_GTE_LTE_queryTime_DATE_RANGE,
                                            search_IN_organ,
                                            search_operOrgRange,
                                            search_EQ_errornum,self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.list[0].errorpath)
        return ret.list[0].queryid

    def test_c_down_error(self):
        '''下载错误文件'''
        queryid = self.get_page()
        ret = EntBatchQueryRequest.down_error(queryid,self.cookie)
        Log.info(ret)
        size = download('企业批量错误文件dhcc_ent_batch_queryDtest_c_down_error%s.xls'%time.strftime('%Y%m%d%H%M%S',time.localtime()),ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)
    def test_d_jump(self):
        '''跳转查询记录'''
        authType = self.file_data.get('authType')
        ret = EntBatchQueryRequest.jump(authType,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000',ret.code)
        self.assertIn('',ret.msg)





if __name__ == "__main__":
    pass